package com.example.tianling.admin.service.Impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tianling.admin.service.ActivateService;
import com.example.tianling.admin.service.UserDataService;
import com.example.tianling.dao.ActivateMapper;
import com.example.tianling.dao.UserMapper;
import com.example.tianling.entity.ActivateEntity;
import com.example.tianling.entity.ArticleEntity;
import com.example.tianling.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ActivateServiceImpl
        extends ServiceImpl<ActivateMapper, ActivateEntity>
        implements ActivateService {
    @Autowired
    private ActivateMapper activateMapper;
//加载刷新论坛页面
   public List<Map<String, Object>> findActivate(String startTime,String endTime){

       QueryWrapper<ActivateEntity> queryWrapper = new QueryWrapper<>();
       queryWrapper.select("DATE(activate_time) AS date", "COUNT(DISTINCT user_id) AS user_count")
               .ge("activate_time", startTime)
               .lt("activate_time", endTime)
               .groupBy("DATE(activate_time)");
       return activateMapper.selectMaps(queryWrapper);
   }

    @Override
    public Void updateActivate(String userId) {
        boolean result = this.lambdaUpdate()
                .eq(ActivateEntity::getUserId, userId)
                .set(ActivateEntity::getActivateTime, new Date())
                .update();
        if (result == false) {
            ActivateEntity activate = new ActivateEntity();
            activate.setUserId(userId);
            activate.setActivateTime(new Date());
            baseMapper.insert(activate);
        }
        return null;
    }
}
